# -*- coding: utf-8 -*-
"""
TG按钮组件 - TgButton
基础按钮组件，支持多种主题和尺寸
"""
from PySide6.QtWidgets import QPushButton
from ...style_manager import StyleManager


class TgButton(QPushButton):
    """TG按钮组件"""
    
    def __init__(self, text="", color_theme='primary', size='small', parent=None, **kwargs):
        # 兼容旧参数名：允许使用 theme= 作为 color_theme 的别名
        if 'theme' in kwargs and isinstance(kwargs['theme'], str):
            color_theme = kwargs['theme']
        super().__init__(text, parent)
        # 初始化TG组件属性
        self._component_name = self.__class__.__name__
        self._is_initialized = False
        self._style_applied = False
        self._theme = 'default'
        self._size_hint = 'medium'
        
        # 设置组件特定属性
        self.color_theme = color_theme
        self.button_size = size  # 避免与内置size属性冲突
        
        # 初始化组件
        self.initialize()
    
    @property
    def component_name(self):
        """获取组件名称"""
        return self._component_name
    
    @property
    def is_initialized(self):
        """检查组件是否已初始化"""
        return self._is_initialized
    
    @property
    def style_applied(self):
        """检查样式是否已应用"""
        return self._style_applied
    
    @property
    def theme(self):
        """获取主题"""
        return self._theme
    
    @theme.setter
    def theme(self, value):
        """设置主题"""
        if self._theme != value:
            self._theme = value
            self.apply_style()
    
    def setup_ui(self):
        """设置用户界面"""
        # QPushButton的基本设置已在__init__中完成
        pass
    
    def apply_style(self):
        """应用样式"""
        StyleManager.apply_button_style(self, self.text(), self.color_theme, self.button_size)
        self._style_applied = True
    
    def initialize(self):
        """初始化组件"""
        if not self._is_initialized:
            self.setup_ui()
            self.apply_style()
            self._is_initialized = True
            self._style_applied = True
    
    def set_theme(self, color_theme):
        """设置主题色"""
        self.color_theme = color_theme
        self.apply_style()
    
    def set_size(self, size):
        """设置尺寸"""
        self.button_size = size
        self.apply_style() 